<?php
/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// | FaceBook 連携 assist
// +---------------------------------------------------------------------------+
// $Id: plugins/assistfb/functions.inc
//20111122 tsuchitani AT ivywe DOT co DOT jp http://www.ivywe.co.jp/
//last update 20111122


if (strpos ($_SERVER['PHP_SELF'], 'functions.inc') !== false) {
    die ('This file can not be used on its own.');
}


$pi_name         = 'assistfb';


//言語ファイル
$langfile = $_CONF['path'] . 'plugins/assistfb/language/'
          . $_CONF['language'] . '.php';

if (file_exists ($langfile)) {
    include_once ($langfile);

} else {
    include_once ($_CONF['path'] . "plugins/{$pi_name}/language/japanese_utf-8.php");
}

//@@@@@---->
//custom 言語ファイル
$langfile_custom = $_CONF['path'] . 'plugins/assistfb/custom/'
          . $_CONF['language'] . '.php';

if (file_exists ($langfile_custom)) {
    include_once ($langfile_custom);
}
//@@@@<-----

//設定ファイル
include_once ($_CONF['path'] . 'plugins/assistfb/config.php');

//$_ASSISTFB_CONF['facebook_phpsdk']=$_CONF['path'] . 'facebook/';;
if ($_ASSISTFB_CONF['facebook_phpsdk']<>"") {
	if (file_exists ($_ASSISTFB_CONF['facebook_phpsdk'].'facebook.php')) {
		require_once $_ASSISTFB_CONF['facebook_phpsdk'].'facebook.php';
	}
}


//自動タグ関連の関数
include_once ($_CONF['path'] . "plugins/{$pi_name}/functions_autotag.inc");






// +---------------------------------------------------------------------------+
// | Geeklog Plugin API Implementation                                         |
// +---------------------------------------------------------------------------+

// +---------------------------------------------------------------------------+
// | 現在インストールされているバージョン取得
// | 書式 plugin_chkVersion_assistfb
// +---------------------------------------------------------------------------+
function plugin_chkVersion_assistfb ()
{
    global $_ASSISTFB_CONF;

    return $_ASSISTFB_CONF['version'];
}





// +---------------------------------------------------------------------------+
// | 機能  プラグイン更新:バージョンナンバーの更新
// | 書式 plugin_upgrade_assistfb
// +---------------------------------------------------------------------------+
function plugin_upgrade_assistfb ()
{
	global $_TABLES;
	global $_ASSISTFB_CONF;

    // the plugin needs these functions so complain when they doesn't exist
    if (!function_exists ('COM_truncate') ||
        !function_exists ('MBYTE_strpos')) {
        return 3002;
    }

    // no db changes - just update the version numbers
    DB_query ("UPDATE {$_TABLES['plugins']} SET pi_version = '{$_ASSISTFB_CONF['version']}', pi_gl_version = '" . VERSION . "' WHERE pi_name = 'assistfb'");

    return true;
}


// +---------------------------------------------------------------------------+
// | 機能  プラグインアンインストール                                          |
// | 書式 plugin_autouninstall_databox                                             |
// +---------------------------------------------------------------------------+
function plugin_autouninstall_assistfb ()
{
    // (1) 削除するテーブル
 
    // (2) 削除するグループ名
    $out['groups'][]='AssistFB Admin';
    // (3) 削除するfeatures
    $out['features'][]='assistFB.admin';
    // (4) 削除するphp_blocks
    $out['php_blocks']=array();
    // (5) 削除する vars */
    $out['vars']=array();

    //
    global $_TABLES;

    $sql="DELETE  FROM {$_TABLES['vars']} ";
    $sql.=" WHERE name LIKE 'assistfb%'";
    DB_query($sql);
	
    return $out;

}
/**
* ☆★現在のユーザは権利があるのをチェック
*
* @return        boolean       Returns true if moderator
*
*/
function plugin_ismoderator_assistfb()
{
    //return SEC_hasRights ('assistfb.moderate');
    //return SEC_hasRights ('userfb.moderate');
    return true;
}





// +---------------------------------------------------------------------------+
// | 機能  プラグインのアイコン取得
// | 書式 plugin_geticon_assistfb
// +---------------------------------------------------------------------------+

function plugin_geticon_assistfb ()
{
    global $_CONF;

    return $_CONF['site_url'] . '/images/icons/plugins.gif';
}

// +---------------------------------------------------------------------------+
// | 機能  管理画面メニュ
// | 書式 plugin_cclabel_assistfb
// +---------------------------------------------------------------------------+
function plugin_cclabel_assistfb()
{
    global $_CONF;

    if (SEC_hasRights('assistfb.admin')) {
        return array('assistfb',$_CONF['site_admin_url'] . "/plugins/assistfb/index.php",$_CONF['site_url'] . '///images/icons/plugins.gif');
    }
    return "";

}

// +---------------------------------------------------------------------------+
// | 機能  管理者メニュ表示
// | 書式 plugin_getadminoption_assistfb
// +---------------------------------------------------------------------------+
// | 戻値 nomal:管理者メニュリンク
// +---------------------------------------------------------------------------+
function plugin_getadminoption_assistfb()
{
	global $_CONF;
	global $_TABLES;
    global $LANG_ASSISTFB_ADMIN;

    if (SEC_hasRights ('assistfb.admin') ){
        //$cnt = DB_getItem ($_TABLES['assist_assists'], 'COUNT(*)');
        $cnt=0;
        return array ($LANG_ASSISTFB_ADMIN['piname'],
                      $_CONF['site_admin_url'] . '/plugins/assistfb/index.php'
                      );
    }	
    return "";

}
/**
* Provide URL of a documentation file
*
* @param   string  $file   documentation file being requested, e.g. 'config'
* @return  mixed           URL or false when not available
*/
function plugin_getdocumentationurl_assistfb(
	$file
) {
	global $_CONF;

	static $doc_url = NULL;

	if ($doc_url === NULL) {
		switch ($file) {
			case 'index':
			case 'config':
				$lang = COM_getLanguageName();
				$path = 'admin/plugins/assistfb/docs/';
				if (!file_exists($_CONF['path_html'] . $path . $lang . '/assistfb.html')) {
					$lang = 'japanese';//'english';
				}
		
				$doc_url = $_CONF['site_url'] . '/' . $path . $lang . '/assistfb.html';
				break;

			default:
				$doc_url = FALSE;
				break;
		}
	}
	
	return $doc_url;
}

/**
* Provides text for a Configuration tooltip
*
* @param    string  $id     Id of config value
* @return   mixed           Text to use regular tooltip, NULL to use config 
*                           tooltip hack, or empty string when not available
*/
function plugin_getconfigtooltip_assistfb(
	$id
){
	// Use config tooltip hack where tooltip is read from the config documentation
	return NULL;
}

?>
